//
//  IMIMediaFrameworkBase.h
//  MiHome
//
//  Created by 阎超 on 10/05/2017.
//  Copyright © 2017 小米移动软件. All rights reserved.
//

#ifndef IMIMediaFrameworkBase_h
#define IMIMediaFrameworkBase_h

#import "IMIMediaFrameworkProtocol.h"
#import "IMICommon_ErrorCode.h"

@interface IMIMediaFrame : NSObject

typedef NS_ENUM(NSInteger, IMIFrameDataType) {
    IMIFrameDataType_Unknown = 0,
    IMIFrameDataType_Encode_H264 = 0x0001,
    IMIFrameDataType_Encode_H265,
    IMIFrameDataType_Encode_MPEG,
    IMIFrameDataType_Encode_SVAC,
    IMIFrameDataType_Encode_JPEG,
    IMIFrameDataType_Encode_AAC = 0x0101,
    IMIFrameDataType_Encode_MP3,
    IMIFrameDataType_Encode_G711a,
    IMIFrameDataType_Encode_G711u,
    IMIFrameDataType_Encode_G726,
    IMIFrameDataType_Decode_YV12 = 0x0201,
    IMIFrameDataType_Decode_I420,
    IMIFrameDataType_Decode_NV12,
    IMIFrameDataType_Decode_RGB24,
    IMIFrameDataType_Decode_RGB32,
    IMIFrameDataType_Decode_PCM_BIT = 0x0301,
    IMIFrameDataType_Decode_PCM_FLOAT,
};

typedef NS_ENUM(NSInteger, IMIFrameType) {
    IMIFrameType_Unknown = 0,
    IMIFrameType_I_FRAME = 1,
    IMIFrameType_P_FRAME = 2,
    IMIFrameType_B_FRAME = 3,
    IMIFrameType_AUDIO_FRAME = 10,
    IMIFrameType_OTHER_FRAME = 20,
};

typedef NS_ENUM(NSInteger, IMIFrameInfo) {
    IMIFrameInfo_Unknown = 1 << 1,
    IMIFrameInfo_Live = 1 << 2,
    IMIFrameInfo_OSD = 1 << 3,
};

@property (nonatomic, assign) NSInteger videoWidth;
@property (nonatomic, assign) NSInteger videoHeight;
@property (nonatomic, assign) NSInteger videoRate;
@property (nonatomic, assign) NSInteger frameTimeStamp;
@property (nonatomic, assign) NSInteger frameTimeStampSec;
@property (nonatomic, assign) NSInteger frameIndex;//TUTK Index
@property (nonatomic, assign) NSInteger frameCount;
@property (nonatomic, assign) IMIFrameDataType frameDataType;
@property (nonatomic, assign) IMIFrameType frameType;
@property (nonatomic, assign) IMIFrameInfo frameInfo;
@property (nonatomic, strong) NSData* frameData;
@property (nonatomic, assign) NSInteger audioSampleRate;
@property (nonatomic, assign) CVPixelBufferRef pixelBufferRef;
@property (nonatomic, assign) NSInteger auidoChannel;
@property (nonatomic, assign) NSInteger audioBitsPerSample;

+ (instancetype)initWithData:(NSData*)data;
+ (instancetype)initWithBytes:(void*)data withLength:(int)len;
- (void*)getBytes;
- (NSUInteger)getLength;

@end

@class IMIPipelineBase;
@interface IMISourceBase : NSObject <IMISourceBaseProtocol> {
@protected
    IMIPipelineBase* _pipelineBase;
}

- (instancetype)initWithFlag:(NSInteger)flag withBase:(IMIPipelineBase*)base;
- (void)fini;
- (NSInteger)putSomething:(NSString*)name withValue:(id)value;
- (NSInteger)getSomething:(NSString*)name withValue:(id)value;
- (void)videoDynamicTransformationEvent:(NSInteger)width andHeight:(NSInteger)height;
- (void)audioDynamicTransformationEvent;
- (NSInteger)intputFrame:(IMIMediaFrame*)frame;
- (IMIMediaFrame*)getFrame;

@end

@interface IMICodecBase : NSObject <IMICodecBaseProtocol> {
@protected
    IMIPipelineBase* _pipelineBase;
}

- (instancetype)initWithFlag:(NSInteger)flag withBase:(IMIPipelineBase*)base;
- (void)fini;
- (NSInteger)putSomething:(NSString*)name withValue:(id)value;
- (NSInteger)getSomething:(NSString*)name withValue:(id)value;
- (void)videoDynamicTransformationEvent:(NSInteger)width andHeight:(NSInteger)height;
- (void)audioDynamicTransformationEvent;
- (NSInteger)transformFrame:(IMIMediaFrame*)inFrame withResult:(IMIMediaFrame*)outFrame;
- (NSInteger)setDecoderType:(IMIDecoderType)type;

@end

@interface IMIOutputBase : NSObject <IMIOutputBaseProtocol> {
@protected
    IMIPipelineBase* _pipelineBase;
}

- (instancetype)initWithFlag:(NSInteger)flag withBase:(IMIPipelineBase*)base;
- (void)fini;
- (NSInteger)putSomething:(NSString*)name withValue:(id)value;
- (NSInteger)getSomething:(NSString*)name withValue:(id)value;
- (void)videoDynamicTransformationEvent:(NSInteger)width andHeight:(NSInteger)height;
- (void)audioDynamicTransformationEvent;
- (NSInteger)setTerminal:(id)terminal;
- (NSInteger)refresh:(id)param;
- (NSInteger)outputFrame:(IMIMediaFrame*)frame withTime:(NSInteger)time;
- (UIImage*)snapshotPicture;
- (NSInteger)enhanceRender:(IMIEnhanceRenderAlgoType)algoType;

@end

@interface IMIPipelineBase : NSObject <IMIPipelineBaseProtocol>

@property (nonatomic, strong) IMISourceBase* sourceBase;
@property (nonatomic, strong) IMICodecBase* codecBase;
@property (nonatomic, strong) IMICodecBase* subcodecBase;
@property (nonatomic, strong) IMIOutputBase* videoBase;
@property (nonatomic, strong) IMIOutputBase* audioBase;

- (instancetype)initWithFlag:(NSInteger)flag;
- (void)fini;
- (NSInteger)putSomething:(NSString*)name withValue:(id)value;
- (NSInteger)getSomething:(NSString*)name withValue:(id)value;
- (NSInteger)startVideoPlayer:(id)terminal withDecodeBloack:(fMediaStreamDataBlock)fBlock;
- (NSInteger)stopVideoPlayer;
- (NSInteger)startAudioPlayer:(id)terminal withDecodeBloack:(fMediaStreamDataBlock)fBlock;
- (NSInteger)stopAudioPlayer;
- (NSInteger)startTalk:(fMediaStreamDataBlock)fBlock;
- (NSInteger)stopTalk;
- (NSInteger)deliverFrame:(IMIMediaFrame*)frame;
- (UIImage*)snapshotPicture:(fAsyncCaptureBlock)fBlock;
- (void)play:(id)terminal;
- (void)pause;
- (NSInteger)getCurrentPosition;

@end

#endif /* IMIMediaFrameworkBase_h */
